﻿using AutoMapper;
using B.S.BaseData.suyuan.ApiWrite.Account.Command;
using B.S.BaseData.suyuan.InforStances.Interface;
using B.S.BaseData.Suyuan.Command;
using B.S.BaseData.Suyuan.Dommain;
using MediatR;
using Microsoft.VisualBasic;

namespace B.S.BaseData.suyuan.ApiWrite.Account.CommandHeader
{
    public class AddtraceabilityCommandHeader : IRequestHandler<AddtraceabilityCommand, ApiResult<object>>
    {
        private readonly IMapper mapper;
        private readonly IBaseRepository<JiBeninformation> InforBase;

        public AddtraceabilityCommandHeader(IMapper mapper, IBaseRepository<JiBeninformation> inforBase)
        {
            this.mapper = mapper;
            this.InforBase = inforBase;
        }
        /// <summary>
        /// 添加基本信息
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<ApiResult<object>> Handle(AddtraceabilityCommand request, CancellationToken cancellationToken)
        {
            ApiResult<object> result = new ApiResult<object>();
            result.Code = APIEnum.添加成功;
            result.Msg = APIEnum.添加成功.ToString();

            var mas = mapper.Map<JiBeninformation>(request);
            mas.CreateTime = DateTime.Now;
            mas.UpdateTime =null;
            var res = await InforBase.AddEntity(mas);
            result.data= res;
            return await Task.FromResult(result);
        } 

    }
}
